#include "hspda.as"
//	sortnotegpĂ̂
#include "hsp3util.as"
//	arrayloadgpĂ̂

title "LINE COUNTER 0.3.1"

//	s𒲂ׂtH_PATH
	PATH=dir_cur
//	ʕ\pmesboxp
	to_MB=""
//	ChJ[hmesboxp
	to_sel_MB=""
screen 0,640,480
;*reset
	cls
//	̃{^ƃtH_FILE̍s\
	button "s",*get_line
;	button "jump",*jump
	pos 70,0
//	buttonƃtH_I
	button "select",*select
	pos 0,24
//	ɑI𒆂PATH\
//	ɒړ͂ĂԂOK
	input PATH,480,24
	pos 0,48
	sel=0
	pos 180,48
//	ׂs\pmesbox
	mesbox to_MB,460,332,0	
	pos 140,0
//	buttonƌ݂̃fBNgFILEꗗ\
	button "ꗗ",*show
	pos 210,0
//	button "check",*gqz
//	button "check",*check
//	button "ړ",*chg
	pos 0,48
//	s𒲂ׂgqIchkbox
	mes "gqI"
	chkbox ".hsp",f_hsp
	chkbox ".as",f_as
	chkbox ".txt",f_txt
	chkbox ".hsh",f_hsh
	chkbox ".hss",f_hss
//	ChJ[h͗pmesbox
	mes "ChJ[h͗p"
	mesbox to_sel_MB,180,270,5
	stop
*gqz
//	s𒲂ׂiIԁjgq̐
	c_num=0
//	s𒲂ׂgqIchkboxONɂȂĂ+1
	if f_hsp==1:c_num++
	if f_as==1:c_num++
	if f_txt==1:c_num++
	if f_hsh==1:c_num++
	if f_hss==1:c_num++
//	s𒲂ׂiIԁjgq
//	`Ŋi[镶z
	sdim cs_tmp,c_num,256
	i=0
//	s𒲂ׂgqIchkboxONɂȂĂ
//	zɑ
	if f_hsp==1{cs_tmp.i="*.hsp":i++}
	if f_as==1 {cs_tmp.i="*.as" :i++}
	if f_txt==1{cs_tmp.i="*.txt":i++}
	if f_hsh==1{cs_tmp.i="*.hsh":i++}
	if f_hss==1{cs_tmp.i="*.hss":i++}
//	ChJ[h͗pmesbox̒gnotesel
	notesel to_sel_MB
//	m[gpbh擾p
	sss=""
//	m[gpbh̍sJԂ
	repeat notemax
//	m[gpbhsǂ݂
	noteget sss,cnt
//	ǂ݂ssȂ
	if sss!=""{
//	s𒲂ׂ̐+1
		c_num++
//	ׂɑ
		cs_tmp.i=sss
		i++
	loop
//	logmes str(c_num)
//	repeat c_num
//	logmes cs_tmp.cnt
//	loop
	return
//	PATH̖\\ׂ
//	PATH̖\\łȂΖ\\
*check
//	PATH\\ŌČʂi[
//	-1ɂȂĂ烋[v𔲂
	flag=0
//	PATH\\ŌJnʒu
	loc=0
//	񐔁idebugpj
	cc=0
//	PATH̒lɑ
	l=strlen(PATH)
//	̌ʂ-1łȂ胋[v
	while flag!=-1
		flag=instr(PATH,loc,"\\")
//	ʂ-1łȂ̂
//	Jnʒuƌ񐔂Z
		if flag!=-1{loc+=flag+1:cc++}
	wend
	logmes str(l)
	logmes str(loc)
	logmes str(cc)
	if l!=loc{
//	\\łȂ̂
//	i\\lloc͂j
//	PATH̖\\ZinputboxXV
		tmp_on_check=PATH+"\\"
		objprm 2,tmp_on_check
	}
	return
;*chg
;	noteget dir,sel
;	chdir dir
;	goto *reset

//	ɍFILEQ
*get_files
	gosub *gqz
//	m[gpbhp
	to_note_on_get_files=""
	notesel to_note_on_get_files
//	gq̐JԂ
	repeat c_num
//	cs_tmp.cntɂ̓ChJ[h+gq`œĂ
//	cs_tmp.cntɂЂFILE𕶎`Ŏ擾
		dirlist dirbuf,cs_tmp.cnt
//	Zm[gpbh߂̑Ώۂ
		 to_note_on_get_files+=dirbuf
	loop
//	FILEQW܂̂Ŏ̏
	gosub *write_dat
	return

//	dFILE폜"files.dat"FILEQ
*write_dat
//	擾FILEQ\[g
//	sortnotehspda.as̖
	sortnote to_note_on_get_files,0
	s="":ss=""
*begin_of_for
	for i,0,(notemax-1),1
		noteget s,i
		noteget ss,(i+1)
//	݂̃m[gpbh̍sƎ̍sȂ
		if s==ss{
			notedel i
//	݂̃m[gpbh̍s폜
//	JԂŏȂ
			goto *begin_of_for
		}
	next
//	ЂFILEQ"files.dat"ɏ
	notesave "files.dat"
	return
	
//	wFILE̍sƑŜ̍s𒲂ׂĕ\
*get_line
//	file"files.dat"ɏ
	gosub *get_files
//	ׂfileǂݍސ̕z
	sdim files,64,1024
//	arrayload"hsp3util.as"̖
//	filezɓǂݍ
	arrayload "files.dat",files
//	m[gpbh̑Ώ
	t=""
	notesel t
	
//	FILE̍s̍vi[
	notemax_count=0
//	mesbox\p
	to_MB_b=""

//	file̐JԂ
	foreach files
//	PATH̖\\ׂ
//	PATH̖\\łȂΖ\\
		gosub *check
		LPATH=PATH+files.cnt
		noteload LPATH
//	g[^̍sɃm[gpbh̍sZ
		notemax_count+=notemax
//	mesboxɒǉ\邽߂̉̕Z
		tmp_b=""+LPATH+"\n"+notemax+"\n"
		to_MB_b+=tmp_b
	loop
//	mesboxɒǉ\邽߂̉̕Z
	to_MB_b+="\nTotal:"+notemax_count
//	mesbox̒gXV
	objprm 3,to_MB_b
	stop
;*jump
;	chdir PATH
;	goto *reset
//	ׂtH_I
*select
//	FILEIdialoggp
	dialog "",16
//	Ԃlsɑ
	s=refstr
//	IFILẼfBNgssɑ
	ss=getpath(s,32)
//	IFILẼfBNginputboxɕ\
	objprm 2,ss
	stop
//	FILEꗗ\pTu[`
*show
	to_show=""
//	FILEꗗto_showɑ
	dirlist to_show,"*.*
//	ʕ\pmesboxdirlisťʂo
	objprm 3,to_show
	stop"